#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PLL pair<ll,ll>
const ll N=2e5+10;
ll last0;
ll last1;
ll dp[N];
ll n;
ll a[N],c[N];
ll ans=0;
bool flag=true;
vector<PLL> last;
void DP(){
	ll i=1;
	while(i<=n){
		ll c0=(last0==-1)?0:(dp[i-1]+(a[i]==a[last0])*a[i]);
		ll c1=(last1==-1)?0:(dp[i-1]+(a[i]==a[last1])*a[i]);
		dp[i]=max(c0,c1);
		if(i==n){
			ans=max(dp[n],ans);
			if(last.empty()){
				return;
			}
			else{
				i=last[last.size()-1].first;
				last0=last[last.size()-1].second;
				last.pop_back();
				last1=i;
				i++;
			}
		}
		else{
			if(c0==c1){
				last.push_back({i,last0});
				last0=i;
				i++;
			}
			else if(c0>c1){
				last0=i;
				i++;
			}
			else{
				last1=i;
				i++;
			}
		}
	}
}
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t;
	cin>>t;
	while(t--){
		ans=0;
		memset(dp,0,sizeof dp);
		cin>>n;
		for(ll i=1;i<=n;i++){
			cin>>a[i];
		}
		last0=-1;
		last1=-1;
		DP();
		cout<<ans<<"\n";
	}
	return 0;
}
